<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-7-25
 * Time: 下午1:40
 */

namespace common\components\sms;

use yii\httpclient\Client;

set_time_limit(0);
header("Content-Type: text/html; charset=UTF-8");
/**
 * 定义程序绝对路径
 */
define('SCRIPT_ROOT',  dirname(__FILE__).'/lhwt/');
require_once SCRIPT_ROOT.'include/Client.php';

/**
 * 联合维拓
 * Class Lhwt
 * @package common\components\sms
 */
class Lhwt extends Sms
{
    const NAME = "联合维拓";

    public function sendSms($mobiles, $content)
    {
        $client = $this->getClient();
//        $statusCode = $client->sendSMS($mobiles,$content.'【易商金融】', date("YmdHis"), '', 'UTF-8');
        $statusCode = $client->sendSMS($mobiles,$content.'【易商新程】', "", '', 'UTF-8');
        return $statusCode;
    }

    public function login()
    {
        $client = $this->getClient();
        $login = $client->login();
        var_dump($login);
    }

    /**
     * @return \Client
     */
    private function getClient()
    {
        /**
         * 网关地址
         */
        $gwUrl = 'http://sdk.univetro.com.cn:6200/sdk/SDKService';

        /**
         * 序列号,请通过联合维拓销售人员获取
         */
        $serialNumber = Config::$lhwt['serialNumber'];

        /**
         * 密码,请通过联合维拓销售人员获取
         */
        $password = Config::$lhwt['password'];

        /**
         * 登录后所持有的SESSION KEY，即可通过login方法时创建
         */
        $sessionKey = Config::$lhwt['sessionKey'];

        /**
         * 连接超时时间，单位为秒
         */
        $connectTimeOut = 2;

        /**
         * 远程信息读取超时时间，单位为秒
         */
        $readTimeOut = 10;

        $proxyhost = false;
        $proxyport = false;
        $proxyusername = false;
        $proxypassword = false;

        $client = new \Client($gwUrl,$serialNumber,$password,$sessionKey,$proxyhost,$proxyport,$proxyusername,$proxypassword,$connectTimeOut,$readTimeOut);
        /**
         * 发送向服务端的编码，如果本页面的编码为GBK，请使用GBK
         */
        $client->setOutgoingEncoding("UTF-8");
        return $client;
    }
}